package demo;

public class Demo16 {
    public static void main(String[] args) {
        /*
            将一个整数转换为7 进制
         */
//        int n = 66;
        int n = -66;
        String s =  Integer.toString(n,16);
        System.out.println(s);
        s = toString(-66,16);
        System.out.println(s);
    }

    static char[] digi={

    };

    public static String toString(int num,int radix){
//        StringBuilder builder = new StringBuilder();
        char[] chs = new char[32];
        //chs = [0 0 0 0 0 ... 0 - 1 2 3 ]
        //index
        boolean negative = false;//先定义数字前面为整数
        if (num<0){//消除负数
            num = -num;
            negative = true;
        }
        int index = chs.length-1;//设定数组长度
        do {
            int n = num%radix;//3
//            builder.append(n);
            char c = digi[n];//指针已向下移
            chs[index--] = c;//将数值装入数组
            //System.out.println(n);
            //System.out.println(num);
            num/=radix;
        }while (num!=0);
        if (negative){
            chs[index--] = '-';
        }
        return new String(chs,index+1,chs.length-index-1);
    }
}
